
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace Com.Phyfun.Business
{
	#region Adv

	/// <summary>
	/// Adv object for NHibernate mapped table 'Advs'.
	/// </summary>
    public class Adv : BizObject
		{
		#region Member Variables
		
		protected int _id;
		protected string _zone;
		protected string _code;
		protected DateTime _pubDate;
		protected int _flag;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public Adv() { }

        public Adv(int id) { if (id != 0)ObjectBroker.Load(this, id); }

		public Adv( string zone, string code, DateTime pubDate, int flag )
		{
			this._zone = zone;
			this._code = code;
			this._pubDate = pubDate;
			this._flag = flag;
		}

		#endregion

		#region Public Properties

		public virtual int Id
		{
			get {return _id;}
			set {_id = value;}
		}

        public virtual string Zone
		{
			get { return _zone; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Zone", value, value.ToString());
				_zone = value;
			}
		}

        public virtual string Code
		{
			get { return _code; }
			set
			{
				if ( value != null && value.Length > int.MaxValue)
					throw new ArgumentOutOfRangeException("Invalid value for Code", value, value.ToString());
				_code = value;
			}
		}

        public virtual DateTime PubDate
		{
			get { return _pubDate; }
			set { _pubDate = value; }
		}

        public virtual int Flag
		{
			get { return _flag; }
			set { _flag = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is Adv))
				throw new InvalidCastException("This object is not of type Adv");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((Adv)obj).Id);
					break;
				case "Zone":
					relativeValue = (this.Zone != null) ? this.Zone.CompareTo(((Adv)obj).Zone) : -1;
					break;
				case "Code":
					relativeValue = (this.Code != null) ? this.Code.CompareTo(((Adv)obj).Code) : -1;
					break;
				case "PubDate":
					relativeValue = (this.PubDate != null) ? this.PubDate.CompareTo(((Adv)obj).PubDate) : -1;
					break;
				case "Flag":
					relativeValue = (this.Flag != null) ? this.Flag.CompareTo(((Adv)obj).Flag) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (Adv.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
